package com.example.demo.zaqizabatest;

/**
 * @ClassName HannuotaQuestion
 * @Author lys4134
 * @Date 2021/08/20 15:32:18
 * @Description HannuotaQuestion
 * @Version 1.0
 **/
public class 汉诺塔问题 {

    private static int count = 0;

    /**
     *  汉诺塔问题
     *  @param {int} n 要移动的盘子个数
     *  @param {String} a a柱子(开始)
     *  @param {String} b b柱子
     *  @param {String} c c柱子(结束)
     *  @returns 
     */
    public static void hanoiTower(int n, String a, String b, String c) {
        if (n < 1) {
            System.out.println("汉诺塔的层数不得小于一");
        } else if (n == 1) {
            move(n, a, c);
        } else {
            hanoiTower(n - 1, a, c, b);
            move(n, a, c);
            hanoiTower(n - 1, b, a, c);
        }
    }

    private static void move(int num, String a1, String c1) {
        count++;
        System.out.println("将" + num + "从" + a1 + "移到" + c1);
    }

    public static void main(String[] args) {
        hanoiTower(9, "a", "b", "c");
        System.out.println("count = " + count);
    }
}
